﻿using System;
using System.Collections.Generic;
 
using System.Text;
 
using System.Drawing;
using System.Windows.Forms;
using AuditUpload.model;

namespace AuditUpload.gui
{
    class guis
    {
        private Form parentMDI;
        private Panel parentPanel;
        private int labelIndex = 100;
        private int labelY = -20;
        public guis(Form frm, Panel panel = null)
        {
            parentMDI = frm;
            parentPanel = panel;
        }

        public void addLabel(progress prog, string Text, subForm frm)
        {
            //this.IsMdiContainer = true;
            frm.MdiParent = parentMDI;
            frm.Parent = parentPanel;
            parentPanel.Controls.Add(frm);
            //================
            frm.StartPosition = FormStartPosition.Manual;
            frm.Location = new Point(10, 10);
            frm.Dock = DockStyle.Fill;
            frm.Parent.Padding = new Padding(20, 20, 20, 20);
            frm.FormBorderStyle = FormBorderStyle.None;
            fixTexts(frm.Controls);

            linkLabel label = new linkLabel(frm, prog);

            label.BackColor = System.Drawing.SystemColors.Control;
            int buttonHeight = 50;
            labelY = labelY + buttonHeight;
            label.Location = new System.Drawing.Point(0, labelY);
            label.Name = "label_" + prog.ToString();
            label.Size = new System.Drawing.Size(224, buttonHeight);
            //label.Width = 185;
            label.TextAlign = ContentAlignment.MiddleCenter;
            label.BackColor = System.Drawing.SystemColors.Control;
            label.Margin = new Padding(0, 0, 0, 0);
            labelIndex++;
            label.TabIndex = labelIndex;

            label.Text = Text;
            label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;

            Global.labeltoShow.Add(label);
        }
        private static void TextboxSelect(object sender, EventArgs e)
        {
            TextBox tb = (TextBox)sender;
            tb.SelectAll();
        }
        public static void fixTexts(Control.ControlCollection ctrls)
        {
            foreach (Control ctrl in ctrls)
            {
                if (ctrl is TextBox)
                {
                    TextBox tb = (TextBox)ctrl;
                    tb.Height = 30;
                    tb.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    tb.Enter += new System.EventHandler(TextboxSelect);
                    tb.Click += new System.EventHandler(TextboxSelect);
                }
                else if (ctrl is Label)
                {
                    Label lb = (Label)ctrl;
                    lb.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                }
                else if (ctrl is Button)
                {
                    //Label lb = (Label)ctrl;
                    ctrl.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                }
            }

        }
    }

    public class subForm : Form
    {
        public progress FormNum { get; set; }
        public virtual void refresh()
        {

        }
    }
    public class linkLabel : System.Windows.Forms.Label
    {
        public subForm _linkForm;
        public linkLabel(subForm linkForm, progress prog)
        {
            this._linkForm = linkForm;
            this._linkForm.FormNum = prog;
        }
        public void FormOn(subForm oriform)
        {
            if (oriform != null)
            {
                oriform.Hide();
                Global.labeltoShow[(int)oriform.FormNum].BackColor = System.Drawing.SystemColors.Control;
            }
            /*for (int i = 0; i < Global.labeltoShow.Count; i++) {
                Global.labeltoShow[i].BackColor= System.Drawing.SystemColors.Control;
            }*/
            this._linkForm.Show();
            this._linkForm.refresh();
            if ((int)this._linkForm.FormNum != 0)
            {
                Global.userDatas.setprocess(this._linkForm.FormNum);
            }
            this.BackColor = System.Drawing.ColorTranslator.FromHtml("#fcfcfc");
        }
        /*public void FormOff()
        {
            this._linkForm.Hide();

            this.BackColor = System.Drawing.SystemColors.Control;
        }*/
    }
}
